/*
 * Copyright 2007 Rob Nielsen
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * 	http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.googlecode.proxymatic.core;

import java.io.Serializable;
import java.util.List;
import java.util.Map;

public class ProxyConfiguration implements Serializable {
    private final RuntimeContext runtimeContext;
    private final Map<MethodSpec, MethodInvoker> methodHandlerMap;
    private final List<ExceptionHandler> exceptionHandlers;
    private final ProxyBuilder proxyBuilder;

    public ProxyConfiguration(RuntimeContext runtimeContext, Map<MethodSpec, MethodInvoker> methodHandlerMap,
            List<ExceptionHandler> exceptionHandlers, ProxyBuilder proxyBuilder) {
        this.runtimeContext = runtimeContext;
        this.methodHandlerMap = methodHandlerMap;
        this.exceptionHandlers = exceptionHandlers;
        this.proxyBuilder = proxyBuilder;
    }

    public RuntimeContext getRuntimeContext() {
        return runtimeContext;
    }

    public Map<MethodSpec, MethodInvoker> getMethodHandlerMap() {
        return methodHandlerMap;
    }

    public List<ExceptionHandler> getExceptionHandlers() {
        return exceptionHandlers;
    }

    public ProxyBuilder getProxyBuilder() {
        return proxyBuilder;
    }

    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (o == null || getClass() != o.getClass()) {
            return false;
        }
        ProxyConfiguration that = (ProxyConfiguration) o;
        if (!proxyBuilder.equals(that.proxyBuilder)) {
            return false;
        }
        if (!runtimeContext.sameImplementations(that.runtimeContext)) {
            return false;
        }
        return true;
    }

    public int hashCode() {
        int result;
        result = runtimeContext.hashCode();
        result = 31 * result + proxyBuilder.hashCode();
        return result;
    }
}
